use std::env;
use std::path::PathBuf;
fn main() {
    if env::var_os("CARGO_FEATURE_RT").is_some() {
        let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
        let device_file = if env::var_os("CARGO_FEATURE_AT32F403").is_some() {
            "src/at32f403/device.x"
        } else if env::var_os("CARGO_FEATURE_AT32F403A").is_some() {
            "src/at32f403a/device.x"
        } else if env::var_os("CARGO_FEATURE_AT32F407").is_some() {
            "src/at32f407/device.x"
        } else if env::var_os("CARGO_FEATURE_AT32F413").is_some() {
            "src/at32f413/device.x"
        } else if env::var_os("CARGO_FEATURE_AT32F415").is_some() {
            "src/at32f415/device.x"
        } else if env::var_os("CARGO_FEATURE_AT32F421").is_some() {
            "src/at32f421/device.x"
        } else {
            panic!("No device features selected");
        };
        std::fs::copy(device_file, out.join("device.x")).unwrap();
        println!("cargo:rustc-link-search={}", out.display());
        println!("cargo:rerun-if-changed=device.x");
    }
    println!("cargo:rerun-if-changed=build.rs");
}
